﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ReporteSATT;

namespace UI_SATT
{
    public partial class FrmReportes : Form, ServiceSATT.ui.IUiListadoPersona
    {
        public FrmReportes()
        {
            InitializeComponent();
            treeView1.ExpandAll();
        }
        ServiceSATT.TipoPersona tipo_;
        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            try
            {
                ReporteEntidades reporte = new ReporteEntidades();
                ListadoPersona persona = new ListadoPersona();
                this.Viewer1.ReportSource = null;
                GbPersonas.Visible = false;
                switch (e.Node.Name)
                {
                    case "ListadoFederacion":
                        this.Viewer1.Visible = true;
                        this.Viewer1.ReportSource = reporte.ListadoFederacion();
                        break;
                    case "ListadoClub":
                        this.Viewer1.Visible = true;
                        this.Viewer1.ReportSource = reporte.ListadoClub();
                        break;
                    case "ListadoSede":
                        this.Viewer1.Visible = true;
                        this.Viewer1.ReportSource = reporte.ListadoSedes();
                        break;
                    case "ListadoAfiliado":
                        this.Viewer1.Visible = true;
                        this.Viewer1.ReportSource = persona.ListadoAfiliado();
                        break;
                    case "ListadoArbitros":
                        this.Viewer1.Visible = true;
                        this.Viewer1.ReportSource = persona.ListadoArbitro();
                        break;
                    case "ListadoEmpleado":
                        this.Viewer1.Visible = true;
                        this.Viewer1.ReportSource = persona.ListadoEmpleado();
                        break;
                    case "HistoriaArbitro":
                        GbPersonas.Text = "Historial de un Arbitro";
                        this.Viewer1.Visible = false;
                        ServiceSATT.IPersonaService person = new ServiceSATT.PersonaService();
                        tipo_ = ServiceSATT.TipoPersona.Arbitro;
                        person.ListarPersonas(this);
                        GbPersonas.Visible = true;
                        break;
                    case "HistorialJugadores":
                        GbPersonas.Text = "Historial de un Jugador";
                        ServiceSATT.IPersonaService afiliado = new ServiceSATT.PersonaService();
                        tipo_ = ServiceSATT.TipoPersona.Afiliado;
                        afiliado.ListarPersonas(this);
                        this.Viewer1.Visible = false;
                        GbPersonas.Visible = true;
                        break;
                    case "RankingJugadores":
                        ReporteRankig rank = new ReporteRankig();
                        this.Viewer1.Visible = true;
                        this.Viewer1.ReportSource = rank.ListadoRanking(TipoRanking.Varones);
                        break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void FrmReportes_Load(object sender, EventArgs e)
        {

        }

        #region IUiListadoPersona Members

        public ServiceSATT.TipoPersona Tipo
        {
            get { return tipo_; }
        }

        public DataTable Listado
        {
            set
            {
                CboPersonas.DataSource = value;
                CboPersonas.DisplayMember = "Apellido";
                CboPersonas.ValueMember = "Dni";
                CboPersonas.Text = string.Empty;
                CboPersonas.SelectedIndex = -1;
            }
        }

        #endregion

        private void BtnGenerar_Click(object sender, EventArgs e)
        {
            BtnGenerar.Enabled = false;
            if (GbPersonas.Text == "Historial de un Arbitro")
            {
                HistorialTorneo arbi = new HistorialTorneo();
                GbPersonas.Visible = false;
                this.Viewer1.Visible = true;
                this.Viewer1.ReportSource = arbi.HistorialArbitro(Convert.ToInt32(CboPersonas.SelectedValue), CboPersonas.Text);
            }
            else
            {
                HistorialTorneo juga = new HistorialTorneo();
                GbPersonas.Visible = false;
                this.Viewer1.Visible = true;
                this.Viewer1.ReportSource = juga.HistorialJugador(Convert.ToInt32(CboPersonas.SelectedValue), CboPersonas.Text);
            }
            BtnGenerar.Enabled = true;
        }
    }
}
